package com.aids_malaria.ui.datacollect;

import android.opengl.Visibility;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aids_malaria.R;
import com.aids_malaria.app.Constant;
import com.aids_malaria.base.BaseFragment;
import com.aids_malaria.util.AuthUtil;
import com.aids_malaria.util.ToastUtil;

import butterknife.BindView;
import butterknife.OnClick;

public class DataCollectFragment extends BaseFragment {

    @BindView(R.id.ll_data_get)
    LinearLayout ll_data_get;
    @BindView(R.id.ll_people_data)
    LinearLayout ll_people_data;
    @BindView(R.id.ll_administrative_village_related_data)
    LinearLayout ll_administrative_village_related_data;

    @BindView(R.id.tv_back)
    TextView tv_back;

    @BindView(R.id.tv_administrative_village_data_collect_back)
    TextView tv_administrative_village_data_collect_back;

    private static DataCollectFragment instance;

    public static DataCollectFragment getInstance() {
        if(null == instance){
            instance = new DataCollectFragment();
        }
        return instance;
    }
    public boolean sholdBackPage(){
        if (ll_data_get.getVisibility() != View.VISIBLE){
            return true;
        }
        return false;
    }

    public void backPage(){
        if (ll_people_data.getVisibility() == View.VISIBLE){
            ll_people_data.setVisibility(View.GONE);
            ll_data_get.setVisibility(View.VISIBLE);
            return;
        }
        if( ll_administrative_village_related_data.getVisibility() == View.VISIBLE){
            ll_administrative_village_related_data.setVisibility(View.GONE);
            ll_data_get.setVisibility(View.VISIBLE);
        }

    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_data_collect;
    }

    @OnClick({R.id.tv_data_get1,R.id.tv_data_get2,R.id.tv_data_get1_1,R.id.tv_data_get1_2,
            R.id.tv_data_get1_3,R.id.tv_data_get1_4,R.id.tv_data_get1_5,R.id.tv_back,
            R.id.tv_administrative_village_data_collect,R.id.tv_mosquito_borne_data_collect,
            R.id.tv_administrative_village_data_collect_back})
    public void onClick(View view){
        Bundle bundle = null;
        switch (view.getId()){
            case R.id.tv_data_get2:
                ll_data_get.setVisibility(View.GONE);
                ll_administrative_village_related_data.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_back:
                ll_people_data.setVisibility(View.GONE);
                ll_data_get.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_data_get1:
                ll_data_get.setVisibility(View.GONE);
                ll_people_data.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_data_get1_1:
                if (!AuthUtil.isHaveAuthByCode(Constant.COLLECT_PERSON_BASE_DATA)){
                    ToastUtil.showNoPermission();
                    return;
                }
                bundle=  new Bundle();
                bundle.putInt(DataCollectActivity.BUSY_TYPE,1);
                bundle.putInt(DataCollectActivity.WAY_COLLECT,DataCollectActivity.WAY_BASE);
                startActivity(DataCollectActivity.class,bundle);
                break;
            case R.id.tv_data_get1_2:
                if (!AuthUtil.isHaveAuthByCode(Constant.COLLECT_TREATMENT_DIAGNOSIS)
                    && !AuthUtil.isHaveAuthByCode(Constant.COLLECT_TREATMENT_TEST)
                    && !AuthUtil.isHaveAuthByCode(Constant.COLLECT_TREATMENT_MEDICATION)
                    && !AuthUtil.isHaveAuthByCode(Constant.COLLECT_TREATMENT_SOURCE_OF_INFECTION)
                    && !AuthUtil.isHaveAuthByCode(Constant.COLLECT_TREATMENT_TREATMENT_OF_EPIDEMIC_FOCUS)){
                    ToastUtil.showNoPermission();
                    return;
                }
                bundle=  new Bundle();
                bundle.putInt(DataCollectActivity.BUSY_TYPE,1);
                bundle.putInt(DataCollectActivity.WAY_COLLECT,DataCollectActivity.WAY_HEAL);
                startActivity(DataCollectActivity.class,bundle);
                break;
            case R.id.tv_data_get1_3:
                if (!AuthUtil.isHaveAuthByCode(Constant.COLLECT_TREATMENT_PAST_MEDICAL_HISTORY)){
                    ToastUtil.showNoPermission();
                    return;
                }
                bundle=  new Bundle();
                bundle.putInt(DataCollectActivity.BUSY_TYPE,1);
                bundle.putInt(DataCollectActivity.WAY_COLLECT,DataCollectActivity.WAY_HISTORY);
                startActivity(DataCollectActivity.class,bundle);
                break;
            case R.id.tv_data_get1_4:
                if (!AuthUtil.isHaveAuthByCode(Constant.COLLECT_TREATMENT_DRUG_SAFETY)){
                    ToastUtil.showNoPermission();
                    return;
                }
                bundle=  new Bundle();
                bundle.putInt(DataCollectActivity.BUSY_TYPE,1);
                bundle.putInt(DataCollectActivity.WAY_COLLECT,DataCollectActivity.WAY_MEDICINE_SECURE);
                startActivity(DataCollectActivity.class,bundle);
                break;
            case R.id.tv_data_get1_5:
                if (!AuthUtil.isHaveAuthByCode(Constant.COLLECT_TREATMENT_PERSONNEL_ACQUISITION)){
                    ToastUtil.showNoPermission();
                    return;
                }
                startActivity(DataQueryActivity.class);
                break;
            case R.id.tv_administrative_village_data_collect:
                if (!AuthUtil.isHaveAuthByCode(Constant.COLLECT_VILLAGE)){
                    ToastUtil.showNoPermission();
                    return;
                }
                startActivity(VillageDataCollectActivity.class);
                break;
            case R.id.tv_mosquito_borne_data_collect:
                if (!AuthUtil.isHaveQueryAuthByCode(Constant.COLLECT_MOSQUITO_BORNE)){
                    ToastUtil.showNoPermission();
                    return;
                }
                startActivity(MosquitoBorneDataActivity.class);
                break;
            case R.id.tv_administrative_village_data_collect_back:
                ll_administrative_village_related_data.setVisibility(View.GONE);
                ll_data_get.setVisibility(View.VISIBLE);
                break;
        }
    }

}
